// pages/user/collect/collect.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    size: 10,
    isLoaded: false,
    isFirstTip: true,
    list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    token = getApp().globalData.token;
    this.getDetail();
  },

  getDetail() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'forum/collection/topic',
      method: 'GET',
      data: {
        token: token,
        page: this.data.page,
        size: this.data.size
      },
      success: (res) => {
        if (res.rowCount == this.data.list.length) {
          this.data.isLoaded = true;
          return 
        }
        res.list.map(m => {
          m.headImg = m.forumImg
        })
        this.setData({
          list: this.data.list.concat(res.list),
        })
      }
    })
  },

  toPostDetail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/find/detail/detail?id=' + id,
    })
  },

  onReachBottom() {
    if (this.data.isLoaded) {
      if (this.data.isFirstTip) {
        wx.showToast({
          title: '已加载完全部数据',
          icon:'none'
        })
      }
      this.data.isFirstTip = false;
      return;
    }
    this.data.page += 1;
    this.getDetail();
  }  
})
